<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\AccLogin;
use App\Services\Acc as Service;

class AccController extends Controller
{
    protected Service $service;

    public function __construct()
    {
        $this->service = new Service();
    }

    public function login(AccLogin $request)
    {
        $data = $request->only([
            'acc_lg_name',
            'acc_lg_pwd',
        ]);

        $acc = $this->service->login($data['acc_lg_name'], $data['acc_lg_pwd']);

        return $this->success('success', [
            'token' => $acc['acc_token'],
            'acc' => $acc,
        ]);
    }

    public function me()
    {
        $token = request()->header('Token');

        $user = $this->service->getUser($token);

        return $this->success('success', ['acc' => $user]);
    }
}
